import os

# 指定目录路径
directory = r"C:\Users\Anyphasy\Downloads\2024校友活动娱乐_百度图片搜索_files"
review_ids = [
    45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
    55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
    65, 66, 67, 68, 69
]

img_urls = []
moment_id = 1
i=0
index=0
temp_img_list=[]
# 遍历目录中的文件
for filename in os.listdir(directory):
    # 检查文件名是否以"u="开头并且以"JPEG"结尾
    if filename.startswith("u=") and filename.endswith("JPEG"):
        # 1. 添加前缀并输出
        url = "https://img2.baidu.com/it/" + filename
        # print(url)
        url='"'+url+'"'

        temp_img_list.append(url)
        i+=1
        if i==5 and index<len(review_ids):
            #逗号链接输出，格式化为下面格式
            # ["https://example.com/images/tree1.jpg", "https://example.com/images/tree2.jpg"]

            # print('['+','.join(temp_img_list)+']')
            tmpstr ='['+ ','.join(temp_img_list) +']'
            print(f'''
            # id为{review_ids[index]}
            UPDATE event_review 
SET review_images = '{tmpstr}'
WHERE review_id = {review_ids[index]};
            ''')
            # 清空
            i=0
            index+=1
            temp_img_list=[]
            

       

print("操作完成")
print('长度为',len(img_urls))